package com.corpgovernment.costcenter.convert;

import com.corpgovernment.costcenter.entity.db.MbOrgProjectInfo;
import com.corpgovernment.costcenter.vo.ProjectInfoVo;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ProjectInfoConvert {

    /**
     * 实体转换
     * @param projectInfoVo
     * @return
     */
    public MbOrgProjectInfo convertFromVo(ProjectInfoVo projectInfoVo){
        MbOrgProjectInfo mbOrgProjectInfo = new MbOrgProjectInfo();
        if(projectInfoVo.getId() !=null && projectInfoVo.getId() > 0){
            mbOrgProjectInfo.setId(projectInfoVo.getId());
        }
        mbOrgProjectInfo.setCompany(projectInfoVo.getCompany());
        mbOrgProjectInfo.setCompanyId(projectInfoVo.getCompanyId());
        mbOrgProjectInfo.setProjectCode(projectInfoVo.getProjectCode());
        mbOrgProjectInfo.setProjectName(projectInfoVo.getProjectName());
        mbOrgProjectInfo.setProjectLeader(projectInfoVo.getProjectLeader());
        mbOrgProjectInfo.setOperatorUid(projectInfoVo.getUserInfo().getUid());
        mbOrgProjectInfo.setOperatorName(projectInfoVo.getUserInfo().getUsername());
        mbOrgProjectInfo.setValid(projectInfoVo.getValid());
        if (projectInfoVo.getValidStartDate() != null){
            mbOrgProjectInfo.setValidStartDate(projectInfoVo.getValidStartDate());
        }
        if (projectInfoVo.getValidEndDate() != null){
            mbOrgProjectInfo.setValidEndDate(projectInfoVo.getValidEndDate());
        }
        mbOrgProjectInfo.setUpdateTime(new Date());
        mbOrgProjectInfo.setIsDelete(Boolean.FALSE);
        return mbOrgProjectInfo;
    }

    /**
     * 实体转换
     * @param mbOrgProjectInfo
     * @return
     */
    public ProjectInfoVo convertToVo(MbOrgProjectInfo mbOrgProjectInfo){
        ProjectInfoVo projectInfoVo = new ProjectInfoVo();
        projectInfoVo.setId(mbOrgProjectInfo.getId());
        projectInfoVo.setCompanyId(mbOrgProjectInfo.getCompanyId());
        projectInfoVo.setCompany(mbOrgProjectInfo.getCompany());
        projectInfoVo.setProjectCode(mbOrgProjectInfo.getProjectCode());
        projectInfoVo.setProjectName(mbOrgProjectInfo.getProjectName());
        projectInfoVo.setProjectLeader(mbOrgProjectInfo.getProjectLeader());
        projectInfoVo.setOperatorUid(mbOrgProjectInfo.getOperatorUid());
        projectInfoVo.setOperatorName(mbOrgProjectInfo.getOperatorName());
        projectInfoVo.setValid(mbOrgProjectInfo.getValid());
        projectInfoVo.setUpdateTime(mbOrgProjectInfo.getUpdateTime());
        projectInfoVo.setValidStartDate(mbOrgProjectInfo.getValidStartDate());
        projectInfoVo.setValidEndDate(mbOrgProjectInfo.getValidEndDate());
        return projectInfoVo;
    }

}
